package com.oa.modules.approvalsec1.controller;

import java.util.Date;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.oa.modules.sys.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.oa.common.utils.AppUtils;
import com.oa.common.utils.PageUtils;
import com.oa.common.utils.R;

import com.oa.modules.approvalsec1.entity.AudioVideoCollectEntity;
import com.oa.modules.approvalsec1.service.AudioVideoCollectService;


/**
 * @author jiangwei
 * @email 785297226@qq.com
 * @date 2021-03-25 11:21:32
 */
@RestController
@RequestMapping("audio/video/collect")
@Api(tags = "音视频收藏相关接口")
public class AudioVideoCollectController extends AbstractController {
    @Autowired
    private AudioVideoCollectService audioVideoCollectService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "列表")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = audioVideoCollectService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApiOperation(value = "信息")
    public R info(@PathVariable("id") String id) {
        AudioVideoCollectEntity audioVideoCollect = audioVideoCollectService.getById(id);
        return R.ok().put("audioVideoCollect", audioVideoCollect);
    }

    /**
     * 收藏
     */
    @PostMapping("/save")
    @ApiOperation(value = "收藏")
    public R save(@RequestBody AudioVideoCollectEntity audioVideoCollect) {
        audioVideoCollect.setId(AppUtils.getUUID());
        audioVideoCollect.setCreateDate(new Date());
//        audioVideoCollect.setCreateOper(getUserId().toString());
        audioVideoCollectService.save(audioVideoCollect);
        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public R update(@RequestBody AudioVideoCollectEntity audioVideoCollect) {
        audioVideoCollect.setUpdateDate(new Date());
        audioVideoCollect.setUpdateOper(getUserId().toString());
        audioVideoCollectService.updateById(audioVideoCollect);
        return R.ok();
    }

    /**
     * 取消收藏
     */
    @PostMapping("/delete")
    @ApiOperation(value = "取消收藏")
    public R delete(@RequestBody AudioVideoCollectEntity audioVideoCollect) {
//        audioVideoCollectService.removeByIds(Arrays.asList(audioVideoCollect.getId()));
        QueryWrapper wra = new QueryWrapper<>().eq("CREATE_OPER", audioVideoCollect.getCreateOper()).eq("AUDIO_VIDEO_ID", audioVideoCollect.getAudioVideoId());
        audioVideoCollectService.remove(wra);
        return R.ok();
    }
}
